<?
/**
 * establish session
 */
ob_start();
require("DShield.php");
require("class.session.php");
require("class.mysql.php");
require("class.diary.php");
require("class.user.php");
require("class.handler.php");
require("forms.php");
require("block.php");
$oDB=new db($SQL['user']);
check_blocklist($oDB);
$bLoggedIn=false;

$nID=0;
$nRate=1;
$bBot=check_bot();

if ( ! $bBot ) {
  $oSession=new session();
  $nPageviews=$oSession->get('pageviews');
  $oSession->set('pageviews',$nPageviews++);
  $sCSRFToken=$oSession->get('csrftoken');
  if ( $_SERVER['REQUEST_METHOD']=='GET' ) {
    $bCSRFToken=check_request('token',$sCSRFToken,'_GET',FALSE);
  } else {
    $bCSRFToken=check_request('token',$sCSRFToken,'_POST',FALSE);
  }
  if ( $_SERVER['REQUEST_METHOD']=='POST' && ! $CSRFToken ) {
    applog('LOG_INFO','no csrf token '.$_SERVER['REQUEST_URI']); 
  }
  $sCSRFToken=sha1(uniqid(rand(),TRUE));
  $oSession->set('csrftoken',$sCSRFToken);
  $nID=$oSession->get('id');
  if ( $nID>0 ) {
    $oUser= new user($nID,$oDB);
    $bLoggedIn=true;
    $nRate=100;
  } else {
    $bLoggedIn=false;
  }
}
$oTodaysDiary=new diary_day($oDB,0,true,true);
$oHandler=new handler($oDB);
$sInfocon=$oDB->simple_query("select status from infocon 
                               order by updated desc limit 1",'','',CACHETIME);
